<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>注册</title>
<style>.b{margin-top:-19px;}
#loginbox .main_input_box{text-align: left;}
#loginbox .main_input_box input{width:50%;}</style>
</head>
<body>
<%@include file="top.jsp" %>
<div id="loginbox">
			<form name="loginForm" id="loginForm" action="${ pageContext.request.contextPath }/register" method="post">
				<div class="control-group b">
					<div class="controls">
						<div class="main_input_box">
							<span class="add-on bg_lg">
							<i>用户</i>
							</span><input style="width: 150px;" type="text" name="uname" id="name" placeholder="请输入用户名" onblur="getNameText()"><span id="nameSpan"></span>
						</div>
					</div>
				</div>
				<div class="control-group b">
					<div class="controls">
						<div class="main_input_box">
							<span class="add-on bg_ly">
							<i>密码</i>
							</span><input style="width: 150px;" type="password" name="upwd" id="pwd" placeholder="请输入密码" onblur="getText(1)"><span id="pwdSpan"></span>
						</div>
					</div>
				</div>
				<div class="control-group b">
					<div class="controls">
						<div class="main_input_box">
							<span class="add-on bg_lg">
							<i>email</i>
							</span><input style="width: 150px;" type="text" name="uemail" id="email" placeholder="请输入邮箱" onblur="getText(2)"><span id="emSpan"></span>
						</div>
					</div>
				</div>
				<div class="control-group b">
					<div class="controls">
						<div class="main_input_box">
							<span class="add-on bg_lg">
							<i>电话</i>
							</span><input style="width: 150px;" type="text" name="uphone" id="tel" placeholder="请输入手机号码" onblur="getText(3)"><span id="telSpan"></span>
						</div>
					</div>
				</div>
				<div class="control-group b">
					<div class="controls">
						<div class="main_input_box">
							<span class="add-on bg_lg">
							<i>简介</i>
							</span><textarea name="umessage" style="resize: none;width: 180px;height: 70px;" placeholder="请输入交友简介"></textarea>
						</div>
					</div>
				</div>
			<input type="submit" id="submit" class="b btn btn-info" value="注册">&nbsp;&nbsp;<input type="reset" class="b btn btn-primary" value="重置">
			</form>
</div>
<%@include file="bottom.jsp" %>
<script>
var aa,b,c,d;
var pPattern = /^(?!([a-zA-Z]+|\d+)$)[a-zA-Z\d]{4,20}$/;
var ePattern = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
var mPattern = /^1[34578]\d{9}$/;
console.log(mPattern.test("15797704351"));
function getText(a){
	switch (a) {
	case 1:
		if(!pPattern.test($("#pwd").val())){
			aa=2;
			$("#pwdSpan").html("<font color='red'>至少4位含字母数字</font>");
		}else {
			aa=1;
			$("#pwdSpan").html("<font color='green'>正确</font>");
		}
		break;
	case 2:
		if(!ePattern.test($("#email").val())){
			b=2;
			$("#emSpan").html("<font color='red'>不正确！</font>");
		}
		else {
			b=1;
			$("#emSpan").html("<font color='green'>正确</font>");
		}
		break;
	case 3:
		if(!mPattern.test($("#tel").val())){
			c=2;
			$("#telSpan").html("<font color='red'>不正确！</font>");
		}
		else {
			c=1;
			$("#telSpan").html("<font color='green'>正确</font>");
		}
		break;
	default:
		break;
	}
	
}
var submitBtn = document.getElementById("submit");
submitBtn.onclick = function(event){
	console.log(aa+","+b+","+c+","+d);
	if(aa==2||b==2||c==2||d!=1){
		
		alert("还不能提交，上面填写有误！");
		//history.back();
		return false;
	}
};

/* $(document).ready(function(){
 */	function getNameText(){
    	var nameVal = $("#name").val();
    	//var nameVal=document.getElementById("name").value;
    	nameVal = $.trim(nameVal);
		$.get("${pageContext.request.contextPath}/validata",{ "uname": nameVal,"time":new Date()},function(data){
			$("#nameSpan").html(data);
		});
		d=1;
	}
/* }); */
  
</script>
</body>
</html>